<!--
 * @description  :举报记录表列表
 * @descriptionDetail:举报记录表列表
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-12-06 18:41:33
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar
      :is-white="false"
      :title="navTitle"
      :custom-back="goBack"
      style="z-index: 99999"
    >
    </theme-navbar>
    <!-- #endif -->
    <view class="content u-page">
      <me-table
        :i="0"
        :top="6"
        :index="0"
        :load-data="loadData"
        :init-load="false"
        ref="mescrollItem0"
      >
        <view slot-scope="d" class="list-item-root">
          <u-swipe-action
            :show="d.data.show"
            :index="d.data.bizUuid"
            :disabled="d.data.swiperDisabled"
            @click="swiperClick"
            @open="swiperOpen"
            :options="d.data.swiperOptions"
          >
            <view class="list-lay" @tap="handlerSelectItem(d.data)">
              <report-card-list-item :itemInfo="d.data"></report-card-list-item>
            </view>
          </u-swipe-action>
        </view>
      </me-table>
    </view>
  </view>
</template>

<script>
import MeTable from '@/components/me-table.vue';
import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
import reportCardListItem from './reportCardListItem';
import intelligenceservice from "@/service/intelligence/intelligence.service";
import {S_DOC_STATUES,} from "@/service/intelligence/mapping/enum.js";
export default {
  components: {
    MeTable,
    reportCardListItem,
  },
  mixins: [MescrollMoreMixin,],
  data() {
    return {
      objInfo:{},
      defaultOrg:undefined,
      type: "",
      param: {},
      user: this.$store.state.userInfo,
    };
  },
  onLoad (opt) {
    this.param = this.getRouteParam();
    console.log(this.param)
    this.clueUuid = opt.uuid;
  },
  methods: {
    // 点击查看详情
    handlerSelectItem (item) {
      console.log(item);
      if (item.handleStatus != S_DOC_STATUES.UNSTARTED && item.handleStatus != S_DOC_STATUES.BACK_TO_EDIT) {
        this.setRouteParam({
          bizUuid:item.bizUuid,
          uuid: item.reportUuid || '',
          detailInfo:this.param.param.detailInfo,
        });
        this.$u.route({
          url:"pages/intelligence/intelligenceFilesAdd/clueReportInfo",
        });
      }
    },
    // 在线案件查询数据
    loadData(page) {
      return new Promise((resolve,reject) => {
        let params = {
          page:page.num,
          limit: page.size,
          clueUuid:this.clueUuid,
        }
        intelligenceservice.clueReportList(params).then(res => {
          if(res.success){
            res.data.forEach(itm => {
              this.getItemCanEdit(itm);
              itm.show = false;
              itm.swiperDisabled = false;
            });
            resolve({
              count: res.count,
              data:res.data,
            });
          }else{
            this.$u.toast(res.msg);
            resolve({
              count: 0,
              data:[],
            });
          }
        }).catch(e => {
          this.$u.toast('请求失败:' + e);
          resolve({
            count: 0,
            data:[],
          });
        });
      })
    },
    updateBackState () {
      this.$refs['mescrollItem0'].refresh();
    },
    // index1是数据索引 index是导航索引
    swiperClick(index1, index){
      let datas = this.$refs.mescrollItem0.listDatas;
      let cur = -1;
      for (let i = 0; i < datas.length; i++) {
        if(datas[i].bizUuid == index1){
          cur = i;
          break;
        }
      }
      if(cur == -1){
        this.$u.toast("选中数据无效");
        return;
      }
      if (index == 0) { // 修改 审批退回或者未开始
        if (datas[cur].handleStatus == S_DOC_STATUES.UNSTARTED || datas[cur].handleStatus == S_DOC_STATUES.BACK_TO_EDIT) {
          let params = datas[cur];
          this.setRouteParam({
            bizUuid:params.bizUuid,
            uuid: params.reportUuid || '',
            detailInfo:this.param.param.detailInfo,
          });
          this.$u.route({
            url: "pages/intelligence/intelligenceFilesAdd/clueReportInfo",
          });
          this.$refs.mescrollItem0.listDatas.map((val, idx) => {
            this.$refs.mescrollItem0.listDatas[idx].show = false;
          });
          return;
        } else if (datas[cur].handleStatus == S_DOC_STATUES.FINISHED || datas[cur].handleStatus == S_DOC_STATUES.INVALID) { // INVALID作废，复制一个接口
          let params = {
            reportUuid:datas[cur].reportUuid,
            type: '',
            clueUuid:datas[cur].clueUuid,
          }
          params.type = datas[cur].handleStatus == S_DOC_STATUES.FINISHED ? 'drop' : 'copy';
          if (datas[cur].handleStatus == S_DOC_STATUES.FINISHED) {
            this.$modal.confirm("是否要作废该记录表？", () => {
              this.drCop(params)
            })
          } else {
            this.drCop(params)
          }
        }
      }
      this.$refs.mescrollItem0.listDatas.map((val, idx) => {
        this.$refs.mescrollItem0.listDatas[idx].show = false;
      });
    },
    drCop(params){
      intelligenceservice.clueReportOption(params).then(res => {
        if (res.success) {
          this.$refs['mescrollItem0'].refresh();
        } else {
          this.$u.toast(res.msg);
        }
      }).catch(err => {
        console.log(err)
      })
    },
    getItemCanEdit(item){
      let disabled = true;
      let swiperOptions = [];
      if(item.handleStatus == S_DOC_STATUES.BACK_TO_EDIT || item.handleStatus == S_DOC_STATUES.UNSTARTED){
        disabled = false;
        swiperOptions.push({
          text: '编辑',
          action:"edit",
          style: {
            backgroundColor: this.$theme.u_type_primary,
          },
        });
      }
      if(item.handleStatus == S_DOC_STATUES.FINISHED && this.param.param.fromType == 'register' && item.orgUuid == this.user.user.org.orgUuid){ // 状态是已完成  且是登记派发可操作
        swiperOptions.push({
          text: '作废',
          action:"deactivate",
          style: {
            backgroundColor: this.$theme.u_type_error,
          },
        });
      }
      if(item.handleStatus == S_DOC_STATUES.INVALID && this.param.param.fromType == 'register' && item.orgUuid == this.user.user.org.orgUuid){  // 状态是已作废 且是登记派发可操作
        swiperOptions.push({
          text: '复制',
          action:"copy",
          style: {
            backgroundColor: this.$theme.u_type_success,
          },
        });
      }
      item.swiperOptions = swiperOptions;
      item.swiperDisabled = disabled;
    },
    swiperOpen(index){
      this.$refs.mescrollItem0.listDatas.map((val, idx) => {
        this.$refs.mescrollItem0.listDatas[idx].show = index == val.bizUuid;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/common/rightMenu.scss";
.page{
  padding: 0;
}
.u-page{
  padding-bottom: 100rpx;
}
.content {
  background-color: #f3f4f5;
  padding-bottom:160rpx;
}
.list-item-root{
  margin: 10px;
  border-radius: 15px;
  overflow: hidden;
}
.list-lay{
  margin: 10px;
}
.nolicence-search-lay {
  background-color: #fff;
  position: fixed;
  // #ifndef H5-DINGDING
  top: 44px;
  // #endif
  // #ifdef H5-DINGDING
  top: 0px;
  // #endif
  z-index: 999;
  width: 100%;
  overflow: hidden;
  padding: $cm-search-padding-row $cm-search-padding-column;
}
.sticky-header {
  background-color: #fff;
  position: fixed;
  /* #ifdef H5-DINGDING  */
  top: 0px;
  /* #endif */
  /* #ifndef H5-DINGDING  */
  top: 44px;
  /* #endif */
  width: 100%;
  margin: auto;
  padding-left: 2.5%;
  padding-right: 2.5%;
  line-height: 40px;
  height: 40px;
  z-index: 999;
  padding: $cm-search-padding-row $cm-search-padding-column;
}
</style>
